package nc.tb.app.plantable.format;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;

import nc.vo.pub.lang.UFDouble;

public class DefaultDataCellRender extends NtbPlanTableCellRender {
	
	protected void setValue(Object value) {
		if (value != null && value instanceof UFDouble) {
			value = ((UFDouble)value).setScale(-2, UFDouble.ROUND_HALF_UP);
		}
		super.setValue(value);
	}
	
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		Component render = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		if (render instanceof JLabel) {
			if (value instanceof UFDouble || value instanceof Double) {
				((JLabel)render).setHorizontalAlignment(SwingConstants.RIGHT);
			}
			else {
				((JLabel)render).setHorizontalAlignment(SwingConstants.LEFT);
			}
		}
		return render;
	}
}
